home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hapyhols / holiday.sx next >
Encoding:
Text File  |  1996-05-21  |  9.6 KB  |  409 lines  |  [TEXT/ttxt]

  1. in module HolidayModule
  2.  
  3.     -- if stationary IV is set, the objects behind it will not be draw
  4.     -- thus a white box appears
  5.  
  6. class Background (GroupPresenter)
  7. inst vars
  8.     bg
  9.     kman
  10.     status : @stop
  11. end
  12.  
  13. --*=============================================================================*
  14. --*       Method name:    importBitmap
  15. --*             Class:    Background
  16. --*             Usage: importBitmap self mediaDir bitmapFile
  17. --*                        mediaDir    - DirRep
  18. --*                        bitmapFile  - String object
  19. --*-----------------------------------------------------------------------------*
  20. --*       Description: Imports the given bitmap from the given directory.
  21. --*=============================================================================*
  22. method importBitmap self {class Background} mediaDir bitmapFile ->
  23. (
  24.     local theStream := getStream mediaDir bitmapFile @readable
  25.     local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap 
  26.     return theBMP
  27. )
  28.  
  29. method setupBG self {class Background} ->
  30. (
  31.     local bgBitmap := (importBitmap self mediaDir "bkground.bmp")
  32.     local background := new TwoDShape boundary:bgBitmap fill:defaultBrush
  33.     background.position := new Point x:0 y:0
  34.     background.stationary := true
  35.     self.bg := background
  36. )
  37.  
  38. method setupKman self {class Background} ->
  39. (
  40.     local kmanBitmap := (importBitmap self mediaDir "kman.bmp")
  41.     local kman := new TwoDShape boundary:kmanBitmap fill:defaultBrush
  42.     kman.position := new Point x:185 y:550
  43.     kman.stationary := true
  44.     self.kman := kman
  45. )
  46.  
  47. method addBG self {class Background} ->
  48. (
  49.     append self self.bg
  50. )
  51.  
  52. method addKman self {class Background} ->
  53. (
  54.     append self self.kman
  55. )
  56.  
  57. method removeBG self {class Background} ->
  58. (
  59.     deleteOne self self.bg
  60. )
  61.  
  62. method removeKman self {class Background} ->
  63. (
  64.     deleteOne self self.kman
  65. )
  66.  
  67. method play self {class Background} ->
  68. (
  69.     self.status := @play
  70. )
  71.  
  72. method stop self {class Background} ->
  73. (
  74.     self.status := @stop
  75. )
  76.  
  77. method startScroll self {class Background} ->
  78. (
  79.     addKman self
  80.     play self
  81. )
  82.  
  83. method stopScroll self {class Background} ->
  84. (
  85.     stop self
  86.     removeBG self
  87. )
  88.  
  89. method tick self {class Background} clk ->
  90. (
  91.     if self.status != @stop do
  92.         self.y := self.y - 3
  93. )
  94.  
  95. method afterInit self {class Background} #rest args ->
  96. (
  97.     setupBG self
  98.     setupKman self
  99.     
  100.     self
  101. )
  102.  
  103.  
  104. class FlyBy (GroupPresenter)
  105. inst vars
  106.     status
  107.     tiny
  108.     banner
  109.     sleigh
  110.     penguins : #()
  111. end
  112.  
  113. --*=============================================================================*
  114. --*       Method name:    importBitmap
  115. --*             Class:    FlyBy
  116. --*             Usage: importBitmap self mediaDir bitmapFile
  117. --*                        mediaDir    - DirRep
  118. --*                        bitmapFile  - String object
  119. --*-----------------------------------------------------------------------------*
  120. --*       Description: Imports the given bitmap from the given directory.
  121. --*=============================================================================*
  122. method importBitmap self {class FlyBy} mediaDir bitmapFile ->
  123. (
  124.     local theStream := getStream mediaDir bitmapFile @readable
  125.     local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap 
  126.     theBMP.invisibleColor := (new RGBColor red:51 green:51 blue:255)
  127.     return theBMP
  128. )
  129.  
  130. --*=============================================================================*
  131. --*       Method name:    importSeries
  132. --*             Class:    FlyBy
  133. --*             Usage: importSeries self mediaDir
  134. --*                        mediaDir    - DirRep
  135. --*-----------------------------------------------------------------------------*
  136. --*       Description: Imports all bitmaps in the given directory.
  137. --*=============================================================================*
  138. method importSeries self {class FlyBy} mediaDir ->
  139. (
  140.     local series := #()
  141.     
  142.     --*=========================================================================*
  143.     --* Import all files in the 'media' folder
  144.     --*=========================================================================*
  145.     for bitmapFile in (getContents mediaDir) do
  146.          append series (importBitmap self mediaDir bitmapFile)
  147.  
  148.     --*=========================================================================*
  149.     --* Complete the animation loop
  150.     --*=========================================================================*
  151.     for i := ((size series) - 1) to 2 by -1 do
  152.         append series series[i]
  153.         
  154.     return series
  155. )
  156.  
  157. method makePenguin self {class FlyBy} series position scale ->
  158. (
  159.     local thePenguin := new Animation series:series scale:scale
  160.     thePenguin.isTransparent := true
  161.     thePenguin.position := position
  162.     append self.penguins thePenguin
  163. )
  164.  
  165. method setupPenguins self {class FlyBy} ->
  166. (
  167.     -- make penguin 1
  168.     local pen1Dir := spawn mediaDir "pen1"
  169.     local penguinList := (importSeries self pen1Dir)
  170.     makePenguin self penguinList (new Point x:1075 y:87) 5
  171.     
  172.     -- make penguin 2
  173.     local pen2Dir := spawn mediaDir "pen2"
  174.     local penguinList := (importSeries self pen2Dir)
  175.     makePenguin self penguinList (new Point x:1002 y:90) 6 
  176.     
  177.     -- make penguin 3
  178.     local pen3Dir := spawn mediaDir "pen3"
  179.     local penguinList := (importSeries self pen3Dir)
  180.     makePenguin self penguinList (new Point x:923 y:71) 8
  181.  
  182.     -- make penguin 4
  183.     local pen4Dir := spawn mediaDir "pen4"
  184.     local penguinList := (importSeries self pen4Dir)
  185.     makePenguin self penguinList (new Point x:849 y:80) 4
  186.  
  187.     self
  188. )
  189.  
  190. method setupSleigh self {class FlyBy} ->
  191. (
  192.     local sleighBitmap := (importBitmap self mediaDir "sleigh.bmp")
  193.     local sleigh := new TwoDShape boundary:sleighBitmap fill:defaultBrush
  194.     sleigh.position := new Point x:7 y:10
  195.     sleigh.stationary := true
  196.     sleigh.isTransparent := true
  197.     self.sleigh := sleigh
  198. )
  199.  
  200. method setupTiny self {class Flyby} ->
  201. (
  202.     local tinyBitmap := (importBitmap self mediaDir "tiny.bmp")
  203.     local tiny := new TwoDShape boundary:tinyBitmap fill:defaultBrush
  204.     tiny.stationary := true
  205.     tiny.isTransparent := true
  206.     self.tiny := tiny
  207. )
  208.  
  209. method addPenguins self {class FlyBy} ->
  210. (
  211.     foreach self.penguins (penguin -> start penguin; append self penguin) undefined
  212. --    print "add penguins"
  213. )
  214.  
  215. method addSleigh self {class FlyBy} ->
  216. (
  217.     append self self.sleigh
  218. --    print "add sleigh"
  219. )
  220.  
  221. method addTiny self {class FlyBy} ->
  222. (
  223.     append self self.tiny
  224.     self.y := 25
  225.     playLeft self
  226. --    print "add tiny"
  227. )
  228.  
  229. method removePenguins self {class FlyBy} ->
  230. (
  231.     foreach self.penguins (penguin -> stop penguin; deleteOne self penguin) undefined
  232. --    print "remove penguins"
  233. )
  234.  
  235. method removeSleigh self {class FlyBy} ->
  236. (
  237.     deleteOne self self.sleigh
  238. --    print "remove sleigh"
  239. )
  240.  
  241. method removeTiny self {class FlyBy} ->
  242. (
  243.     deleteOne self self.tiny
  244. --    print "remove tiny"
  245. )
  246.  
  247. method playRight self {class FlyBy} ->
  248. (
  249.     self.status := @playright
  250. )
  251.  
  252. method playLeft self {class FlyBy} ->
  253. (
  254.     self.status := @playleft
  255. )
  256.  
  257. method stop self {class FlyBy} ->
  258. (
  259.     self.status := @stop
  260. )
  261.  
  262. method tick self {class FlyBy} clk ->
  263. (
  264.     if self.status = @stop do
  265.         return
  266.         
  267.     if (self.status = @playright) then
  268.         self.x := self.x + 3
  269.     else
  270.         self.x := self.x - 3
  271. )
  272. method afterInit self {class FlyBy} #rest args ->
  273. (
  274.     setupPenguins self
  275.     setupSleigh self
  276.     setupTiny self
  277.     
  278.     self
  279. )
  280.  
  281.  
  282.  
  283. class HolidayCard (Window)
  284. inst vars
  285.     background
  286.     flyby
  287.     jingles
  288.     kman
  289. end
  290.  
  291. method initCallBacks self {class HolidayCard} ->
  292. (
  293.     local flyby := self.flyby
  294.     local bg := self.background
  295.     local winClock := self.clock
  296.     local scale := winClock.scale
  297.     
  298.     -- add callback to move flyby across the screen
  299.     addPeriodicCallBack winClock (self -> tick self undefined) flyby #() 1
  300.     -- add callback to move background upward
  301.     addPeriodicCallBack winClock (self -> tick self undefined) bg #() 1
  302.  
  303.     -- add background to window
  304.     addTimeCallBack winClock addBG bg #() 0 false
  305.     
  306.     -- add penguins to window
  307.     addTimeCallBack winClock addPenguins flyby #() 0 false     -- 50
  308.  
  309.     -- add sleigh to window
  310.     addTimeCallBack winClock addSleigh flyby #() 0 false   -- 150 
  311.                                  
  312.      -- remove penguins from window
  313.     addTimeCallBack winClock removePenguins flyby #() 370 false 
  314.  
  315.     -- remove sleigh from window
  316.     addTimeCallBack winClock removeSleigh flyby #() 650 false  
  317.                                 
  318.     -- add tiny to window
  319.     addTimeCallBack winClock addTiny flyby #() 660 false  
  320.     
  321.     -- remove tiny from window
  322.     addTimeCallBack winClock removeTiny flyby #() 980 false 
  323.     
  324.     -- add kman to window and start scrolling
  325.     addTimeCallBack winClock startScroll bg #() 980 false  
  326.  
  327.     -- remove background from window and stop scrolling
  328.     addTimeCallBack winClock stopScroll bg #() 1145 false
  329. )
  330.  
  331. method start self {class HolidayCard} ->
  332. (
  333.     self.clock.rate := 1
  334.     play self.jingles
  335. )
  336.  
  337. method reset self {class HolidayCard} ->
  338. (
  339.     local flyby := self.flyby
  340.     local bg := self.background
  341.     local winClock := self.clock
  342.     local jingles := self.jingles
  343.     
  344.     winClock.rate := 0
  345.     winClock.time := 0
  346.     stop jingles
  347.     
  348.     -- reset jingles 
  349.     playPrepare jingles 1
  350.     gotobegin jingles
  351.     
  352.     -- reset background
  353.     bg.position := new Point x:0 y:0
  354.     emptyout bg
  355.  
  356.     -- reset flyby
  357.     playRight flyby
  358.     flyby.position := new Point x:-1300 y:100
  359.     emptyout flyby
  360. )
  361.  
  362. method stop self {class HolidayCard} ->
  363. (
  364.     self.clock.rate := 0
  365.     stop self.jingles
  366. )
  367.  
  368. method init self {class HolidayCard} #rest args ->
  369. (
  370.     apply nextmethod self boundary:(new rect x2:640 y2:480) \
  371.                           name:"Happy Holidays 1995" \
  372.                           fill:whiteBrush \
  373.                           centered:true args 
  374.     self.clock.rate := 0
  375.     self.clock.scale := 15
  376.     self
  377. )
  378.  
  379. method afterInit self {class HolidayCard} #rest args ->
  380. (
  381.     -- import colormap
  382.     local theStream := getStream mediaDir "bkground.bmp" @readable
  383.     self.colormap := importMedia theImportExportEngine theStream @image @dib @colormap
  384.  
  385.     -- add background
  386.     self.background := new Background
  387.     prepend self self.background
  388.  
  389.     -- add flyby
  390.     self.flyby := new FlyBy
  391.     prepend self self.flyby    
  392.     
  393.     initCallbacks self
  394.     
  395.     -- import jingles
  396.     local theStream := getStream mediaDir "jingles.aif" @readable
  397.     self.jingles := importMedia theImportExportEngine theStream \
  398.                         @sound @aiff @player container:self.title
  399.     self
  400. )
  401.  
  402. method afterLoading self {class HolidayCard} str ->
  403. (
  404.     nextmethod self str
  405.     loadDeep self
  406.     
  407.     reset self
  408. )
  409.